﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Wrappers.WebContext;

namespace IrishSettings
{
    public class ProcessAnonymousUsers
    {
        private readonly HttpRequestWrapper request;
        
        public ProcessAnonymousUsers(HttpRequestWrapper newRequest)
        {
            request = newRequest;
        }

        public string LogonAnonymous()
        {
            HttpCookie current = request.Cookies["IrishSettings.AnonymousId"];
            string name;
            if(current==null)
            {
                name = Guid.NewGuid().ToString();
                current = new HttpCookie("IrishSettings.AnonymousId", name);
                current.Expires = DateTime.Now.AddDays(365);
                request.Cookies.Add(current);   
            }
            else
            {
                //Renew it for another day
                name = current.Value;
                current.Expires = current.Expires.AddDays(1);
                request.Cookies.Set(current);
            }
            return name;
        }

    }
}
